<style>
    .custom-toolbar{padding: 0em 1em 1em 0em;}
</style>
<style>
    .modal-body {max-height: 560px;overflow:hidden;padding: 15px 0 0 0}
    .modal-footer{background-color: white}
    .wizard-nav {
        padding: 15px 0 13px;
        border-bottom: 1px solid #eee;
        margin-top: -15px;
    }
    ul, ol, ul li, ol li {
        margin: 0;
        padding: 0;
        list-style-type: none;
    }
    .wizard-nav li {
        display: inline-block;
        width: 24%;
        text-align: center;
    }
    .wizard-nav li span {
        position: relative;
        display: block;
        margin: 3px auto;
        width: 36px;
        height: 36px;
        text-align: center;
        line-height: 27px;
        border-radius: 50%;
        background: #777;
        border: 4px solid #e2e2e2;
        color: #fff;
    }
    .wizard-nav li span hr {
        position: absolute;
        top: -11px;
        left: 28px;
        width: 188px;
        height: 8px;
        background: #e2e2e2;
        border: 0 none;
    }
    .wizard-nav li.current span {
        background-color: #386d39;
    }
    .steps{
        padding-top: 8px;
        /*width: 3214px;*/
        width: 6000px;
        position: relative;
        left: 0px;
    }
    .steps .step{
        display: inline-block;
        width: 800px;
        vertical-align: top;
    }
    .btn-prev {
        background: #3b3f4e;
        float: left;
    }
    .btn-next {
        background: #3b3f4e;
        float: right;
    }
    .modal-footer {
        margin-bottom: -2px;
    }
    .hide{
        display: none;
    }
    .formInput{
        height: 371px;
        overflow-y: hidden;
        overflow-x: hidden;
    }
    .form-inline i{margin-right: 19px !important;}
</style>
<div class="row-fluid clearfix">
<div class="col-md-12 column">
    <ul class="breadcrumb">
        <li>
            <a href="index.html">首页</a>
        </li>
        <li class="active">
            客户设备绑定
        </li>
    </ul>
</div>
<div class="col-md-12 column">
<div class="col-sm-12 div-page">
<div style="width: 800px;overflow:hidden;margin:auto">
<ol class="wizard-nav">
    <li class="current step1">
        客户基本信息
        <span><hr>1</span>
    </li>
    <li class="step2">
        注册商户信息
        <span><hr>2</span>
    </li>
    <li class="step3">
        绑定设备信息
        <span><hr>3</span>
    </li>
    <li class="step4">
        限额与手续费
        <span>4</span>
    </li>
</ol>
<div class="steps">
<form id="validForm" method="post" action="#" class="form-horizontal layer_msg">
<div id="step1" class="step">
    <div class="formInput">
        <input type="hidden" class="form-control" id="PId" name="PId"/>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">证件类型</label>
            <div class="form-group  col-sm-4">
                <select class="form-control" data-field="CertifiType" id="CertifiType" name="CertifiType" >
                    <!--动态加载-->
                </select>
            </div>
            <label class="col-sm-2 control-label">证件号码</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="CertifiNo" id="CertifiNo" name="CertifiNo" placeholder="证件号码（必输项）"  required/>
            </div>
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label"></label>
            <div class="form-group col-sm-6">
                <button id="queryName" type="button" class="btn btn-primary">查 询</button>
                <span id="tiShi" class="hide">正在查询客户信息，请稍后………………</span>
            </div>
        </div>
        <div id="cusResp" class="hide">
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">客户姓名</label>
                <div class="form-group col-sm-4">
                    <input type="text" class="form-control" data-field="UseName" id="UseName" name="UseName" required />
                </div>
                <label class="col-sm-2 control-label">联系电话</label>
                <div class="form-group  col-sm-4">
                    <input type="text" class="form-control" data-field="Phone" id="Phone" name="Phone" placeholder="手机/座机号码（必输项）"  required />
                </div>
            </div>
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">绑定账号</label>
                <div class="form-group  col-sm-4">
                    <select class="form-control" id="cards">
                        <!--动态加载-->
                    </select>
                </div>
            </div>
            <div class="col-sm-12 hide">
                <label class="col-sm-2 control-label">绑定账号</label>
                <div class="form-group col-sm-4">
                    <input type="text" class="form-control" id="CardNo" name="CardNo" placeholder="银行卡号（必输项）" required />
                </div>
            </div>
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">联系地址</label>
                <div class="form-group  col-sm-4" style="width: 612px;">
                    <input type="text" class="form-control" data-field="Address" id="Address" name="Address" placeholder="详细地址（必输项）" required/>
                </div>
            </div>
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">收益网点<span class="red">*</span></label>
                <div class="form-group form-inline  col-sm-10">
                    <div class="col-sm-5 hidden">
                        <select class="form-control" id="level1" name="level1" style="width: 100%;margin-left: -15px;margin-right: -15px" required>
                        </select>
                    </div>
                    <div class="col-sm-7 hidden">
                        <select class="form-control" id="level2" name="level2" style="width: 100%;margin-left: -15px;margin-right: -15px" required>
                        </select>
                    </div>
                    <div class="col-sm-12 hidden" style="margin-top: 10px">
                        <select class="form-control" id="level3" name="level3" style="width: 100%;margin-left: -15px;margin-right: -15px" required>
                        </select>
                    </div>
                    <input type="text" class="form-control hidden" id="ABISCode" readonly/>
                </div>
            </div>
        </div>

    </div>

    <div class="modal-footer" style="clear: both">
        <button id="modal-btn-next1" type="button" class="btn btn-primary btn-next disabled">下一步</button>
    </div>
</div>
<div id="step2" class="step">
    <div class="formInput">
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">是否开通跨行</label>
            <div class="form-group  col-sm-4">
                <div class="checkbox">
                    <label>

                        <input type="checkbox" id="croBank" checked="checked">
                    </label>
                </div>
            </div>
        </div>
        <div  id="nr">
            <div class="col-sm-12">
                <label class="col-sm-2 control-label">商户信息</label>
                <div class="form-group  col-sm-4">
                    <select class="form-control" id="merchants">
                        <!--动态加载-->
                    </select>
                </div>
            </div>
            <div id="nrr">
                <div class="col-sm-12">
                    <label class="col-sm-2 control-label">商户名称</label>
                    <div class="form-group  col-sm-4">
                        <input type="hidden" class="form-control" id="MerchantId" name="MerchantId"/>
                        <input type="text" class="form-control" id="MerchantName" name="MerchantName" placeholder="商户名称（必输项）" required/>
                    </div>
                    <label class="col-sm-2 control-label">工商注册号</label>
                    <div class="form-group col-sm-4">
                        <input type="text" class="form-control" id="BusergNo" name="BusergNo" placeholder="工商注册号（必输项）" required />
                    </div>
                </div>
                <div class="col-sm-12">
                    <label class="col-sm-2 control-label">税务登记号</label>
                    <div class="form-group  col-sm-4">
                        <input type="text" class="form-control" id="TaxergNo" name="TaxergNo" placeholder="税务登记号（必输项）"  required />
                    </div>
                </div>
            </div>

        </div>
    </div>

    <div class="modal-footer" style="clear: both">
        <button id="modal-btn-prev0" type="button" class="btn btn-primary btn-prev">上一步</button> <button id="modal-btn-next2" type="button" class="btn btn-primary btn-next">下一步</button>
    </div>
</div>
<div id="step3" class="step">
    <div class="formInput">
        <input type="hidden" id="IsKh" name="IsKh" value="01">
        <div class="form-group col-sm-12 category">
            设备信息 :（1.用串口线连接电脑与设备；2.单击“设备编号”输入框即可获取当前设备信息）
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">设备编号</label>
            <div class="form-group col-sm-4">
                <input type="text" class="form-control" id="DeviceId" name="DeviceId" required />
            </div>
            <label class="col-sm-2 control-label">密码键盘编号</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" id="SafeDevId" name="SafeDevId" required />
            </div>
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">定位半径</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="Radius" id="Radius" name="Radius" value="1000" required/>
            </div>
            <label class="col-sm-2 control-label">锁屏时间</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="AppLockTime" id="AppLockTime" name="AppLockTime" value="300" required/>
            </div>
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">设备属组</label>
            <div class="form-group  col-sm-4">
                <select class="form-control" data-field="UserType" id="UserType" name="UserType" placeholder="设备属组（必输项）" required>
                    <!--动态加载-->
                </select>
            </div>
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">安装地址</label>
            <div class="form-group  col-sm-4" style="width: 612px;">
                <input type="text" class="form-control" id="InstallAddr" name="InstallAddr" placeholder="详细地址（必输项）" required/>
            </div>
        </div>
        <div class="form-group col-sm-12 category">
            客户经理信息 :（非必输项）
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">客户经理姓名</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="ManagerName" id="ManagerName" name="ManagerName" placeholder="客户经理姓名"/>
            </div>
            <label class="col-sm-2 control-label">客户经理代码</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="ManagerId" id="ManagerId" name="ManagerId" placeholder="客户经理代码"/>
            </div>
        </div>
        <div class="col-sm-12">
            <label class="col-sm-2 control-label">客户经理电话</label>
            <div class="form-group  col-sm-4">
                <input type="text" class="form-control" data-field="ManagerCont" id="ManagerCont" name="ManagerCont" placeholder="客户经理电话"/>
            </div>
        </div>
    </div>
    <div class="modal-footer" style="clear: both">
        <button id="modal-btn-prev1" type="button" class="btn btn-primary btn-prev">上一步</button>
        <button id="modal-btn-next3" type="button" class="btn btn-primary btn-next">下一步</button>
    </div>
</div>
<div id="step4" class="step">
    <input type="hidden" class="form-control" data-field="OrgId" name="OrgId" readonly/>
    <div class="formInput">
        <div class="form-group col-sm-12 category">
            交易限额 :（初始值由设备属组的值决定）
        </div>
        <div class="col-sm-12" style="clear: both">
            <label class="col-sm-2 control-label">本行单笔限额</label>
            <div class="form-group col-sm-4">
                <input type="text" min="1" Class="form-control" id="CusLmtAmt" name="CusLmtAmt" placeholder="本行单笔限额（必输项）"   required/>
            </div>
            <label class="col-sm-2 control-label">本行日累计限额</label>
            <div class="form-group col-sm-4">
                <input type="text" min="1" class="form-control" id="CusLmtAmtDay" name="CusLmtAmtDay" placeholder="本行日累计限额（必输项）" required/>
            </div>
        </div>
        <div class="col-sm-12 kh">
            <label class="col-sm-2 control-label">跨行单笔限额</label>
            <div class="col-sm-4 form-group">
                <input type="text" min="1" class="form-control" id="CusOtherLmtAmt" name="CusOtherLmtAmt" placeholder="跨行单笔限额（必输项）"  required/>
            </div>
            <label class="col-sm-2 control-label">跨行日累计限额</label>
            <div class="col-sm-4 form-group">
                <input type="text" min="1" class="form-control" id="CusOtherLmtAmtDay" name="CusOtherLmtAmtDay" placeholder="跨行日累计限额（必输项）" required/>
            </div>
        </div>
        <div class="form-group col-sm-12 category">
            手续费设置 :
        </div>
        <div class="col-sm-12 hidden">
            <label class="col-sm-2 control-label">本行手续费</label>
            <div class="form-group col-sm-4">
                <select class="form-control" data-field="FeeCharge" id="FeeCharge" name="FeeCharge" required>
                    <!--<option value="01">按笔收</option>-->
                    <option value="02">按金额</option>
                </select>
            </div>
            <!--<label class="col-sm-2 control-label">手续费</label>
            <div class="form-group  col-sm-4">
                <input type="text" min="0" class="form-control" data-field="FeeFixedAmt" id="FeeFixedAmt" name="FeeFixedAmt" required/>
            </div>-->
        </div>

        <div class="col-sm-12">
            <label class="col-sm-2 control-label">本行折扣率</label>
            <div class="form-group col-sm-4">
                <input type="text" min="0" max="1" maxlength="4" class="form-control" data-field="ABCCardFee" id="ABCCardFee" name="ABCCardFee" placeholder='范围"0.00~1.00"（必输项）' value="0.00" required/>
            </div>
            <label class="col-sm-2 control-label">手续费支付方</label>
            <div class="form-group col-sm-4">
                <select class="form-control" id="PayType" name="PayType" required>
                    <!--<option value="0">转入方付费</option>-->
                    <option value="1" selected>转出方付费</option>
                </select>
            </div>
        </div>
        <!--<div class="col-sm-12">
            <label class="col-sm-2 control-label kh">跨行手续费</label>
            <div class="form-group  col-sm-4 kh">
                <select class="form-control" data-field="OtherCardFee" id="OtherCardFee" name="OtherCardFee" required>
                    <option value="">请选择</option>
                    <option value="0">免费</option>
                    <option value="1" selected>收费</option>
                </select>
            </div>
        </div>-->
    </div>
    <div class="modal-footer" style="clear: both">
        <button id="modal-btn-prev2" type="button" class="btn btn-primary btn-prev">上一步</button>
        <button id="modal-btn-finish" type="submit" class="btn btn-primary btn-finish">完 成</button>
    </div>
</div>
</form>
</div>
</div>

</div>
</div>
</div>

<script>

$(function () {
    /*innitRegularExpression({
        CertifiNo:"id",
        Phone:"phone"
    });*/

    /*标记表单元素中的必输项-Start*/
        $("input[required]").parent().prev().append('<span class="red">*</span>');
        $("select[required]").parent().prev().append('<span class="red">*</span>');
        $("#level1").parent().parent().find('.red').empty();
    /*标记表单元素中的必输项-End*/

    /*表单元素中下拉列表的数据动态生成（证件类型、用户类型）-Start*/
        FormatSelect(globalUrl+"api/Dict?Typeid=0000000005",$("#CertifiType"),"","110001",function(data){});
        FormatSelect(globalUrl+"api/Dict?Typeid=0000000007",$("#UserType"),"请选择","",function(data){});
    /*表单元素中下拉列表的数据动态生成（证件类型、用户类型）-End*/

    /*引导式表单输入-Start*/
        var pointX=["0","-804px","-1608px","-2412px"];
        $("#modal-btn-prev0,#modal-btn-prev1,#modal-btn-prev2,#modal-btn-next1,#modal-btn-next2,#modal-btn-next3").click(function(){
            var id=$(this).attr("id");
            switch (id){
                case "modal-btn-next1":
                    if(!isValidFields($("#validForm"),["Phone","Address","CardNo","level1","level2","level3"])){
                        return;
                    };
                    var flag=true;
                    $.ajax({
                        type: "get",
                        async:false,
                        datatype:"json",
                        url: globalUrl+"api/DeviCustomer?CertifiType="+$("#CertifiType").val()+"&CertifiNo="+$("#CertifiNo").val()+"&CardNo="+$("#CardNo").val(),
                        success: function (resp) {
                            if(!resp.result)
                            {
                                alert(resp.msg);
                                flag=false;
                            }
                        },
                        error:function(){
                            alert("后台未成功返回！");
                        },
                        complete:function(){
                            $("#tiShi").addClass("hide");
                        }
                    });
                    if(!flag) return;
                    break;
                case "modal-btn-next2":
                    if(!isValidFields($("#validForm"),["MerchantName","BusergNo","TaxergNo"])){
                        return;
                    };
                    break;
                case "modal-btn-next3":
                    if(!isValidFields($("#validForm"),["DeviceId","SafeDevId","UserType","InstallAddr"])){
                        return;
                    };
                    break;
            }
            var index=id.substr(14);
            $(".steps").animate({"left":pointX[index]},300);
            $(".wizard-nav>li").removeClass("current");
            $(".wizard-nav>li").eq(index).addClass("current");
        });
    /*引导式表单输入-End*/

    /*收益网点相关-Start*/
        //依据当前登陆用户级别调整收益网点的视图显示
        switch ($.cookie("OperClass")){
            case "1":
                $("#level1").parent().removeClass("hidden");
                FormatSelect(globalUrl+"api/Site?orgid=910",$("#level1"),"请选择","",function(resp){
                    console.log(resp);
                });
                break;
            case "2":
                $("#level1").parent().addClass("hidden");
                $("#level2").empty().parent().removeClass("hidden");
                FormatSelectHasABIS(globalUrl+"api/Site?orgid="+ $.cookie("OrgId"),$("#level2"),"请选择","",function(resp){});
                break;
            case "3":
                $("#level1").parent().addClass("hidden");
                $("#level3").empty().parent().removeClass("hidden");
                FormatSelectHasABIS(globalUrl+"api/Site?orgid="+ $.cookie("OrgId"),$("#level3"),"请选择","",function(resp){});
                break;
            case "4":
                $("#level1,#level2,#level3").parent().addClass("hidden");
                $("#ABISCode").val($.cookie("OrgId")).removeClass("hidden");
                $("input[name='OrgId']").val($.cookie("OrgId"));
                break;
        }
        //收益网点选择，三级联动
        $("#level1").change(function(){
            $("#level2").empty().parent().removeClass("hidden");
            $("#level3").empty().parent().addClass("hidden");

            if($(this).val()!=""){
                FormatSelectHasABIS(globalUrl+"api/Site?orgid="+$(this).val(),$("#level2"),"请选择","",function(resp){
                });
            }
            else{
                $("#level2").parent().addClass("hidden");
                $("#level3").parent().addClass("hidden");
            }
            setFieldsInValid($("#validForm"),["level1","level2"]);
        });
        $("#level2").change(function(){
            $("#level3").empty().parent().removeClass("hidden");

            if($(this).val()!=""){
                FormatSelectHasABIS(globalUrl+"api/Site?orgid="+$(this).val(),$("#level3"),"请选择","",function(resp){
                });
            }
            else{
                $("#level3").parent().addClass("hidden");
            }
            setFieldsInValid($("#validForm"),["level2","level3"]);
        });
        $("#level3").change(function(){
            if($(this).val()!=""){
                var orgid=$(this).val();
                var orgtext=$(this).find("option:checked").text();
                $("#ABISCode").val(orgtext);
                $("input[name='OrgId']").val(orgid);
            }
        });
    /*收益网点相关-End*/

    /*客户信息查询-Start*/
        $("#queryName").click(function(){
        if(!isValidFields($("#validForm"),["CertifiType","CertifiNo"])){
            return;
        };
        $("#tiShi").removeClass("hide");
        $.ajax({
            type: "get",
            async:false,
            datatype:"json",
            url: globalUrl+"api/DeviCustomer?CertifiType="+$("#CertifiType").val()+"&CertifiNo="+$("#CertifiNo").val(),
            //url: "../json/queryResp.json",
            success: function (resp) {
                if(resp.result)
                {
                    buffer=resp.data.Merchants;
                    $("#UseName").val(resp.data.Customer.UseName);
                    $("#PId").val(resp.data.Customer.PId);
                    if(resp.data.CardNos.length==0)
                    {
                        $("#MerchantId").val("9999");
                        $("#CardNo").parent().parent().removeClass("hide");
                        $("#cards").parent().parent().addClass("hide");
                        $("#merchants").parent().parent().addClass("hide");
                    }
                    else
                    {
                        $("#Phone").val(resp.data.Customer.Phone);
                        $("#Address").val(resp.data.Customer.Address);
                        initCards(resp.data.CardNos,$("#cards"));
                        initMerchants(resp.data.Merchants,$("#merchants"));
                        $("#CardNo").val($("#cards").val());
                        if(resp.data.Merchants.length!=0)
                        {
                            for(var i=0;i<buffer.length;i++)
                            {
                                if(buffer[i].MerchantId==$("#merchants").val())
                                {
                                    $("#MerchantId").val(buffer[i].MerchantId);
                                    $("#MerchantName").val(buffer[i].MerchantName).attr("readonly","readonly");
                                    $("#BusergNo").val(buffer[i].BusergNo).attr("readonly","readonly");
                                    $("#TaxergNo").val(buffer[i].TaxergNo).attr("readonly","readonly");
                                    setFieldsValid($("#validForm"),["MerchantName","BusergNo","TaxergNo"]);
                                }
                            }
                        }
                    }
                    $("#CertifiType,#CertifiNo,#UseName").attr("readonly",true);
                    $("#queryName").parent().parent().hide();
                    $("#cusResp").removeClass("hide");
                    $("#modal-btn-next1").removeClass("disabled");
                }
                else
                {
                    alert(resp.msg);
                }
            },
            error:function(){
                alert("后台未成功返回！");
            },
            complete:function(){
                $("#tiShi").addClass("hide");
            }
        });
    });
    /*客户信息查询-End*/

    /*表单填写过程中的一些事件注册-Start*/
        //点击终端编号输入框，获取当前的终端编号和密码键盘编号
        $("#DeviceId").click(function(){
            var termId = P_UploadTermID();
            if(!termId)
            {
                return;
            }
            var padId = P_UploadSafeID();
            if(!padId)
            {
                return;
            }
            $("#DeviceId").val(termId);
            $("#SafeDevId").val(padId);
            setFieldsValid($("#validForm"),["DeviceId","SafeDevId"]);
        });
        //选择或新增商户
        $("#merchants").change(function(){
            if($(this).val()=="9999")
            {
                $("#MerchantId").val("9999");
                $("#MerchantName").val("").removeAttr("readonly");
                $("#BusergNo").val("").removeAttr("readonly");
                $("#TaxergNo").val("").removeAttr("readonly");
                setFieldsInValid($("#validForm"),["MerchantName","BusergNo","TaxergNo"]);
            }
            else
            {
                for(var i=0;i<buffer.length;i++)
                {
                    if(buffer[i].MerchantId==$(this).val())
                    {
                        $("#MerchantId").val($(this).val());
                        $("#MerchantName").val(buffer[i].MerchantName).attr("readonly","readonly");
                        $("#BusergNo").val(buffer[i].BusergNo).attr("readonly","readonly");
                        $("#TaxergNo").val(buffer[i].TaxergNo).attr("readonly","readonly");
                        setFieldsValid($("#validForm"),["MerchantName","BusergNo","TaxergNo"]);
                    }
                }
            }

        });
        //选择或新增卡号
        $("#cards").change(function(){
            if($(this).val()=="9999")
            {
                $("#CardNo").parent().parent().removeClass("hide");
                $("#CardNo").val("");
                setFieldsInValid($("#validForm"),["CardNo"]);
            }
            else
            {
                $("#CardNo").parent().parent().addClass("hide");
                $("#CardNo").val($("#cards").val());
                setFieldsValid($("#validForm"),["CardNo"]);
            }

        });
        //是否开通跨行复选框
        $("#croBank").click(function(){
            $("#nr,.kh").toggleClass("hide");
            $(".kh").hasClass("hide")?$("#IsKh").val("00"):$("#IsKh").val("01");
        });
        //选择用户类别
        $("#UserType").change(function(){
            if(!!$(this).val())
            {
                $.ajax({
                    url:globalUrl+"api/UserType?UserType="+$("#UserType").val(),
                    success:function(resp)
                    {
                        if(resp.result)
                        {
                            $("#CusLmtAmt").val(resp.data.LmtAmt).attr("max",resp.data.LmtAmt);
                            $("#CusLmtAmtDay").val(resp.data.LmtAmtDay).attr("max",resp.data.LmtAmtDay);
                            $("#CusOtherLmtAmt").val(resp.data.OtherLmtAmt).attr("max",resp.data.OtherLmtAmt);
                            $("#CusOtherLmtAmtDay").val(resp.data.OtherLmtAmtDay).attr("max",resp.data.OtherLmtAmtDay);
                            reloadFields($("#validForm"),["CusLmtAmt","CusLmtAmtDay","CusOtherLmtAmt","CusOtherLmtAmtDay"]);
                            setFieldsValid($("#validForm"),["CusLmtAmt","CusLmtAmtDay","CusOtherLmtAmt","CusOtherLmtAmtDay"]);
                        }
                        else
                        {
                            alert(resp.msg);
                        }
                    }
                });
            }

        });

        $("#FeeCharge").change(function(){
            if($(this).val()==="01")
            {
                $("#FeeFixedAmt").parent().css("display","block");
                $("#FeeFixedAmt").parent().prev().css("display","block");
                $.ajax({
                    type: "get",
                    dataType: "json",
                    url:globalUrl+"api/UserType?Usertype="+$("#UserType").val(),
                    success:function(resp){
                        $("#FeeFixedAmt").attr("min",resp.data.FactorageMin).attr("max",resp.data.FactorageMax).attr("placeHolder","取值区间为：["+resp.data.FactorageMin+"～"+resp.data.FactorageMax+"]");
                        $("#validForm").data('formValidation').destroy();
                    }
                });
            }
            else
            {
                $("#FeeFixedAmt").val("");
                $("#FeeFixedAmt").parent().css("display","none");
                $("#FeeFixedAmt").parent().prev().css("display","none");
            }
        });
    /*表单填写过程中的一些事件注册-End*/

    /*验证表单提交-Start*/
        $('#validForm')
            .formValidation({
                err: {
                    container: 'popover'
                },
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                addOns: {
                    i18n: {}
                }
            })
            .formValidation('setLocale', 'zh_CN')
            .on('success.form.fv', function(e) {
                e.preventDefault();
                if(parseInt($("#CusLmtAmt").val())>parseInt($("#CusLmtAmtDay").val()))
                {
                    alert("本行单笔限额应小于本行日累计限额");
                    return;
                }
                if(parseInt($("#CusOtherLmtAmt").val())>parseInt($("#CusOtherLmtAmtDay").val()))
                {
                    alert("跨行单笔限额应小于跨行日累计限额");
                    return;
                }
                $.ajax({
                    type: "post",
                    data:getFormData(),
                    async:false,
                    url: globalUrl+"api/DeviCustomer",
                    success: function (resp) {
                        if(resp.result)
                        {
                            alert(resp.msg);
                            $.ajax({
                                type: "get",
                                url: funUrl,
                                dataType: "html",
                                success: function (result) {
                                    $(".main-body").html(result);
                                    $(".modal").addClass("dropzone");
                                    $('.dropzone').draggable();
                                    $(".breadcrumb .active").text(funName);
                                    $(".modal").attr("data-backdrop","static")
                                }
                            });
                            //$('#modal-Template').modal('hide');
                            //$('#table').bootstrapTable('refresh',{url:globalUrl+"api/Customer?"+$("#queryForm").serialize()});
                        }
                        else
                        {
                            if(resp.msg=="该设备未下密钥，请下密钥")
                            {
                                if(confirm("该设备未下密钥，是否跳转到下载密钥页面？"))
                                {
                                    localStorage.keyDownloadFlag="false";
                                    window.open(location.href);
                                }
                            }
                            else
                            {
                                alert(resp.msg);
                            }
                        }
                    },
                    error:function(){
                        alert("后台未成功返回！");
                    }
                });
            });
    /*验证表单提交-End*/
});
//读取终端序列号
function P_UploadTermID() {
    if(P_CloseCOMport()!="0000")
    {
        alert("关闭串口出错");
        return false;
    }
    //打开串口
    P_OpenCOMport();
    var a = NDV_OCX.UploadTermID();
    if(P_CloseCOMport()!="0000")
    {
        alert("关闭串口出错");
        return false;
    }
    if (a != "" && a != undefined && a != '0014') {
        if(a.length!=20)
        {
            alert("终端编号非20位！");
            return false;
        }
        return a;
    } else {
        alert(a+" 读取终端序列号失败");
        return false;
    }
}

//读取密码键盘序列号
function P_UploadSafeID() {
    if(P_CloseCOMport()!="0000")
    {
        alert("关闭串口出错");
        return false;
    }
    //打开串口
    P_OpenCOMport();
    var a = NDV_OCX.UploadSafeID();
    if(P_CloseCOMport()!="0000")
    {
        alert("关闭串口出错");
        return false;
    }
    if (a != "" && a != undefined && a != '0015') {
        if(a.length!=16)
        {
            alert("密码键盘编号非16位！");
            return false;
        }
        return a;
    } else {
        alert(a+" 读取密码键盘序列号失败");
        return false;
    }

}

//关闭串口
function P_CloseCOMport() {
    return NDV_OCX.CloseCOMport();
}

//打开串口
function P_OpenCOMport() {
    //寻址打开串口
    for (var i = 0; i < 10; i++) {
        var openco = NDV_OCX.OpenCOMport("COM" + i, "9600");
        if (openco == '0000') {
            break;
        }
    }
}
</script>